

package ordenesBeans;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.RowEditEvent;
import java.util.ArrayList;  
import java.util.List; 
import javax.persistence.PersistenceContext;
import ventasBeans.beanVentas;

@ManagedBean(name="bodeg")
@ApplicationScoped
@PersistenceContext
public class bodega implements Serializable {
    private static final long serialVersonUID = 2L;
    private int nobod;
    private String nom_bod;
    private String ubic_bod;
    private int cap_max;
    private String categ;
    
    
    
    beanbodega bodeg;

    public int getNobod() {
        return nobod;
    }

    public void setNobod(int nobod) {
        this.nobod = nobod;
    }

    public String getNom_bod() {
        return nom_bod;
    }

    public void setNom_bod(String nom_bod) {
        this.nom_bod = nom_bod;
    }

    public String getUbic_bod() {
        return ubic_bod;
    }

    public void setUbic_bod(String ubic_bod) {
        this.ubic_bod = ubic_bod;
    }

    public int getCap_max() {
        return cap_max;
    }

    public void setCap_max(int cap_max) {
        this.cap_max = cap_max;
    }

    public String getCateg() {
        return categ;
    }

    public void setCateg(String categ) {
        this.categ = categ;
    }

    
    //------------------------------------------------
    
    List<String> nombrebod = new ArrayList<String>();
    private String bod;

    public String getBod() {
        return bod;
    }

    public void setBod(String bod) {
        this.bod = bod;
    }
    
    public String addBod(){
    nombrebod.add(bod);
    bod="";
    return null;
    }
    
    public List<String> completeBod (String query){
     return nombrebod;   
    }
    //-------------------------------------------------------
    
    public beanbodega getBodeg() {
        return bodeg;
    }

    public void setBodeg(beanbodega bodeg) {
        this.bodeg = bodeg;
    }
    
    private static final ArrayList <beanbodega> orderList = new ArrayList<beanbodega>();
    
    public ArrayList<beanbodega> getOrderList(){
    return orderList;
    }
    
    public String addAction(){
    beanbodega databodega = new beanbodega(this.nobod, this.nom_bod, this.ubic_bod, this.cap_max, this.categ);
    orderList.add(databodega);
    bod=this.nom_bod;
    addBod();
    nobod=0;
    nom_bod="";
    ubic_bod="";
    cap_max=0;
    categ="";
    
    return null;
    }
    
    public void onEdit(RowEditEvent event) {  
        FacesMessage msg = new FacesMessage("Bodega Editada",((beanbodega) event.getObject()).getNom_bod());  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  
       
    public void onCancel(RowEditEvent event) {  
        FacesMessage msg = new FacesMessage("Bodega Eliminada");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        orderList.remove((beanbodega) event.getObject());
    }
    
    /*public void elimbod (bodega b){
    beanbodega databodega = new beanbodega(this.nobod, this.nom_bod, this.ubic_bod, this.cap_max, this.categ);
    orderList.remove(databodega);
    }*/
    
    public void onRemove(RowEditEvent event) {  
        FacesMessage msg = new FacesMessage("Cliente eliminado");   
        FacesContext.getCurrentInstance().addMessage(null, msg); 
        orderList.remove((beanbodega) event.getObject());
    }
    
    /*public void onCancel(RowEditEvent event) { //sirve para solo cancelar la edición 
        FacesMessage msg = new FacesMessage("Edición Cancelada", ((beanbodega) event.getObject()).getNom_bod());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }*/
    
    
    
    
    }
    
    
    
    
    

